<include file="Public/header" />

<include file="Public/menu" />
<!---时间插件-->
<script type="text/javascript" src="/Public/admin/calendar/calendar.js"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak={$ak}"></script>
<link rel="stylesheet" href="__PUBLIC__/admin/calendar/calendar-blue.css"/>
<!-- 内容页 -->
<div class="content-wrapper">
    <!-- 面包屑 -->
    <section class="content-header">
        <h1>
            店铺
            <small>管理</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> 店铺管理</a></li>
            <li class="active">修改店铺</li>
        </ol>
    </section>

    <!-- 内容 -->
    <section class="content"><div class="row"><div class="col-md-12">
        <div class="box box-info">
            <div class="box-header with-border">
                <h3 class="box-title">修改店铺</h3>

                <div class="box-tools">

                    <div class="btn-group pull-right" style="margin-right: 10px">
                        <a href="/manage/store/index" class="btn btn-sm btn-default"><i class="fa fa-list"></i>&nbsp;店铺列表</a>
                    </div>
                </div>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
            <form action="/manage/store/storeUpdate" method="post" accept-charset="UTF-8" id="form" class="form-horizontal" pjax-container="">
                <div class="box-body">
                    <div class="form-group 1">
                        <label class="col-sm-2 control-label">门店名称</label>
                        <div class="col-sm-6">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <input type="text" name="local_name" value="{$store['local_name']}" class="form-control" placeholder="门店名称">
                                <input type="hidden" name="local_id" value="{$store['local_id']}">
                            </div>
                        </div>
                    </div>
                    <div class="form-group 1">
                        <label class="col-sm-2 control-label">登陆名称</label>
                        <div class="col-sm-6">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <input type="text" name="username" value="{$store.username}" class="form-control" placeholder="登陆名称">
                            </div>
                        </div>
                    </div>                    
                    <div class="form-group-error">
                    </div>
                    <div class="form-group 1">
                        <label class="col-sm-2 control-label">登陆密码</label>
                        <div class="col-sm-6">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <input type="password" name="password" value="" class="form-control" placeholder="登陆密码">
                            </div>
                        </div>
                    </div>
                    <div class="form-group 1">
                        <label class="col-sm-2 control-label">配送区域</label>
                        <div class="col-sm-6">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <input type="text" name="area_dispatch" value="{$store.area_dispatch}" class="form-control" placeholder="配送区域">
                            </div>
                        </div>
                    </div>
                    <div class="form-group 1">
                        <label class="col-sm-2 control-label">门店类型</label>
                        <div class="col-sm-6">
                            <div class="input-group">
                                <select name="local_type" class="form-control  select2-hidden-accessible">
                                    <option value="0" <if condition="$store['local_type'] == 0">selected</if>>自营店</option>
                                    <option value="1" <if condition="$store['local_type'] == 1">selected</if>>加盟店</option>
                                    <option value="2" <if condition="$store['local_type'] == 3">selected</if>>租赁店</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="form-group 1">
                        <label class="col-sm-2 control-label">门店编号</label>
                        <div class="col-sm-6">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <input type="text" name="local_number" value="{$store.local_number}" class="form-control" placeholder="门店编号">
                            </div>
                        </div>
                    </div>
                    <div class="form-group 1">
                        <label class="col-sm-2 control-label">门店营业状态</label>
                        <div class="col-sm-6">
                            <div class="input-group">
                                停业 <input type="radio" checked name="local_status" value="0" class="" <if condition="$store['local_status'] == '0'">checked</if>>
                                营业 <input type="radio" name="local_status" value="1" class="" <if condition="$store['local_status'] == '1'">checked</if>>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group 1">
                    <label class="col-sm-2 control-label">门店全称</label>
                    <div class="col-sm-6">
                        <div class="input-group">
                            <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                            <input type="text" name="local_full_name" value="{$store.local_full_name}" class="form-control" placeholder="门店全称">
                        </div>
                    </div>
                </div>
                <div class="form-group 1">
                    <label class="col-sm-2 control-label">营业开始时间</label>
                    <div class="col-sm-6">
                        <div class="input-group">
                            <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                            <input type="text" class="form-control" id="business_begintime" name="business_begintime" value="{$store.business_begintime}" placeholder="营业开始时间">
                        </div>

                    </div>
                </div>
                <div class="form-group 1">
                    <label class="col-sm-2 control-label">营业结束时间</label>
                    <div class="col-sm-6">
                        <div class="input-group">
                            <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                            <input type="text" id="business_endtime" name="business_endtime" value="{$store.business_endtime}" class="form-control" placeholder="营业结束时间" />
                        </div>
                    </div>
                </div>
                <div class="form-group 1">
                    <label class="col-sm-2 control-label">负责人</label>
                    <div class="col-sm-6">
                        <div class="input-group">
                            <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                            <input type="text" name="principal" value="{$store.principal}" class="form-control" placeholder="负责人">
                        </div>
                    </div>
                </div>
                <div class="form-group 1">
                    <label class="col-sm-2 control-label">门店logo</label>
                    <div class="col-sm-6">
                        <input type="file" id="image" data-max-file-count="1" />
                        <input type="hidden" id="image_action"/>
                    </div>
                    <?php if (!empty($store['local_log'])) { ?>
                    <div class="col-sm-6" style="margin-left: 274px; margin-top: 5px;">
                        <img src="/Uploads/{$store['local_log']}" style="height: 100px; ">
                        <span><a class="delete_cat_img" images="local_log" href="#">删除</a></span>
                    </div>
                    <?php } ?>
                </div>

                <div class="form-group 1">
                    <label class="col-sm-2 control-label">门店相册</label>
                    <div class="col-sm-6">
                        <input type="file" id="cat_bg_img"  data-max-file-count="1" />
                        <input type="hidden" id="cat_bg_img_action"/>
                    </div>
                    <?php if (!empty($store['local_photo'])) { ?>
                    <div class="col-sm-6" style="margin-left: 274px; margin-top: 5px;">
                        <img src="/Uploads/{$store['local_photo']}" style="height: 100px; ">
                        <span><a class="delete_cat_img" images="local_photo" href="#">删除</a></span>
                    </div>
                    <?php } ?>
                </div>
                <div class="form-group 1">
                    <label class="col-sm-2 control-label">地图选取</label>
                    <div class="col-sm-6">
                        <div id="storeMap"   style="display: block; height: 400px;"></div>
                    </div>
                </div>
                <div class="form-group 1">
                    <label class="col-sm-2 control-label">所属地区</label>
                    <div class="col-sm-6">
                        <div class="input-group">
                            <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                            <input type="text" name="area_text" id="store_district" value="{$store.area_text}" class="form-control" placeholder="所属地区">
                            <input type="hidden" name="province" id="province" value="{$store.province}" placeholder="省">
                            <input type="hidden" name="city" id="city" value="{$store.city}" placeholder="市">
                            <input type="hidden" name="area" id="area" value="{$store.area}" placeholder="区">
                        </div>
                    </div>
                </div>
                <div class="form-group 1">
                    <label class="col-sm-2 control-label">详细地址</label>
                    <div class="col-sm-6">
                        <div class="input-group">
                            <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                            <input type="text" name="addr" id="store_detailed_address" value="{$store.addr}" class="form-control" placeholder="详细地址">
                        </div>
                    </div>
                </div>
                <div class="form-group 1">
                    <label class="col-sm-2 control-label">经度</label>
                    <div class="col-sm-6">
                        <div class="input-group">
                            <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                            <input type="text" name="store_lnt" id="store_lnt" value="{$store.store_lnt}" class="form-control" placeholder="经度" readonly>
                        </div>
                    </div>
                </div>
                <div class="form-group 1">
                    <label class="col-sm-2 control-label">维度</label>
                    <div class="col-sm-6">
                        <div class="input-group">
                            <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                            <input type="text" name="store_lat" id="store_lat" value="{$store.store_lat}" class="form-control" placeholder="维度" readonly>
                        </div>
                    </div>
                </div>
                <div class="form-group 1">
                    <label class="col-sm-2 control-label">电话</label>
                    <div class="col-sm-6">
                        <div class="input-group">
                            <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                            <input type="text" name="tel" value="{$store.tel}" class="form-control" placeholder="电话">
                        </div>
                    </div>
                </div>
                <div class="form-group 1">
                    <label class="col-sm-2 control-label">手机</label>
                    <div class="col-sm-6">
                        <div class="input-group">
                            <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                            <input type="text" name="mobile" value="{$store.mobile}" class="form-control" placeholder="手机">
                        </div>
                    </div>
                </div>
                <div class="form-group 1">
                    <label class="col-sm-2 control-label">自提备注</label>
                    <div class="col-sm-6">
                        <div class="input-group">
                            <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                            <textarea type="text" name="ziti_remark" class="form-control">{$store.ziti_remark}</textarea>
                        </div>
                    </div>
                </div>
                <div class="form-group 1">
                    <label class="col-sm-2 control-label">周边配送物流名称</label>
                    <div class="col-sm-6">
                        <div class="input-group">
                            <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                            <input type="text" name="myexpress" value="{$store.myexpress|default=C('DEFAULT_EXPRESS')}" data-default="<?php echo C('DEFAULT_EXPRESS');?>" class="form-control" placeholder="周边配送物流名称">
                        </div>
                    </div>
                </div>
                <div class="form-group 1">
                    <label class="col-sm-2 control-label">店铺是否能自己设置周边物流名称</label>
                    <div class="col-sm-6">
                        <div class="input-group">
                            可以 <input type="radio" name="is_byself" value="1" class="" <if condition="$store['is_byself'] eq 1">checked</if>>
                            不行 <input type="radio" name="is_byself" value="0" class="" <if condition="$store['is_byself'] eq 0">checked</if>>
                        </div>
                    </div>
                </div>
                <!-- /.box-body -->
                <div class="box-footer">
                    <div class="col-sm-2">

                    </div>
                    <div class="col-sm-6">

                        <div class="btn-group pull-left">
                            <button type="submit" id="submit" class="btn btn-info pull-right">保存</button>
                        </div>

                    </div>

                </div>
                <!-- /.box-footer -->
            </form>
        </div>

    </div></div>

    </section>
</div>
<!-- 底部 -->
<include file="Public/common_footer" />
<!--上传插件-->
<link rel="stylesheet" href="/Public/admin/fileinput/fileinput.min.css">
<script src="/Public/admin/fileinput/fileinput.min.js"></script>
<link rel="stylesheet" href="/Public/admin/jedate/jedate.css" />
<script src="/Public/admin/jedate/jedate.js"></script>
<script data-exec-on-popstate>
	// 设置时间
	function setJedate(){
		var start = {
			dateCell: "#business_begintime",
			format: "hh:mm"
		};
		var end = {
			dateCell: "#business_endtime",
			format: "hh:mm"
		};
		jeDate(start);
		jeDate(end);
	}
    $(function () {
		setJedate();
        // 上传图片js
        $("#image").fileinput({
            overwriteInitial: true,
            dropZoneEnabled: false,
            uploadUrl: '/admin/upload/index/"',
            language: 'zh',
            showRemove: false,
            maxFileCount: 1,
            browseClass: 'btn btn-primary btn-docup',
            showPreview: true,
            uploadClass: 'btn btn-default btn-docup',
            allowedFileTypes: ["image"],
            browseLabel: "添加图片",
            uploadLabel: "上传图片",
        }).on("fileuploaded", function (event, data, previewId, index) {
            var response = data.response;
            if (data.jqXHR.status == 200) {
                // ajax 成功返回数据写入
                $('.file-preview-frame').eq(index).append("<input class='abc' type='hidden' name='local_log[]' value='"+response+"'>");
            }
        });
        $("#image").on('filecleared', function(event) {
            $("#image_action").val(1);
        });


        $("#cat_bg_img").fileinput({
            overwriteInitial: true,
            dropZoneEnabled: false,
            uploadUrl: '/admin/upload/index/"',
            language: 'zh',
            showRemove: false,
            maxFileCount: 1,
            browseClass: 'btn btn-primary btn-docup',
            showPreview: true,
            uploadClass: 'btn btn-default btn-docup',
            allowedFileTypes: ["image"],
            browseLabel: "添加图片",
            uploadLabel: "上传图片",
        }).on("fileuploaded", function (event, data, previewId, index) {
            var response = data.response;
            if (data.jqXHR.status == 200) {
                // ajax 成功返回数据写入
                $('.file-preview-frame').eq(index).append("<input class='abc' type='hidden' name='local_photo[]' value='"+response+"'>");
            }
        });
        $("#cat_bg_img").on('filecleared', function(event) {
            $("#cat_bg_img_action").val(1);
        });

        $(".delete_cat_img").click(function () {
            var type = $(this).attr('images');
            var this_img = $(this);
            $.get("/manage/store/deleteImg/id/{$store['local_id']}/type/" + type,function(data,status){
                if (data == 1) {
                    this_img.parent().parent().remove();
                }
            });
        });

        //  调取百度API

        var map = new BMap.Map("storeMap");
        var markerTmp;
        map.enableScrollWheelZoom(true);
        var lng="{$store.store_lnt}",lat="{$store.store_lat}";
        if(lng != '' && lat != ''){
            map.centerAndZoom(new BMap.Point(lng,lat),17);
            var marker = new BMap.Marker(new BMap.Point(lng,lat));  // 创建标注
            markerTmp = marker;
            map.addOverlay(marker); //将标注添加到地图中
        }
        else{map.centerAndZoom('重庆',15); //设置地图元素的可视层
        }
//        _getLocation(lng,lat);
        map.addEventListener("click", function(e) {

            if (markerTmp != '') {
                map.removeOverlay(markerTmp);
            }
            lng = e.point.lng;
            document.getElementById("store_lnt").value = lng;
            lat = e.point.lat;
            document.getElementById("store_lat").value = lat;
            //在地图上面描点
            var marker = new BMap.Marker(new BMap.Point(lng, lat));  // 创建标注
            markerTmp = marker;
            map.addOverlay(marker);
            var gc = new BMap.Geocoder();
            //获取地址的数据地址
            var pt = e.point;
            gc.getLocation(pt, function (rs) {
                var addComp = rs.addressComponents;
                var address = addComp.province + addComp.city + addComp.district + addComp.street + addComp.streetNumber;
                var site = addComp.province + addComp.city + addComp.district;
                document.getElementById("store_district").value = site;
                document.getElementById("store_detailed_address").value = address;
                $("#province").val(addComp.province)
                $("#city").val(addComp.city)
                $("#area").val(addComp.district)
            });
        });


        //  表单提交
        $('input[name=is_byself]').on('change', function () {
            if(this.value == '0') {
                var default_name = $('input[name=myexpress]').data('default');
                $('input[name=myexpress]').val(default_name);
            }
        });
		$("#form").validate({
            rules: {
              local_name:{
                required: true,
                rangelength: [2, 50]
              },
              username: {
                required: true,
                isUsername: true
              },
              password: {
                isPassword: true
              },
              mobile: {
                isMobile: true
              },

              tel:{
                isPhone: true
              },
              principal:{
                rangelength: [2, 10]
              },
              business_begintime:{
                isShopTime: true
              },
              business_endtime:{
                isShopTime: true,
                shopTimeBigThan: "#business_begintime"
              },
              ziti_remark:{
                maxlength: 250
              }
            },
            messages:{
                local_name: {     
                    required: "请输入门店名称",
                    rangelength: "门店名称长度在2到50个字符之间"
                },
                username: {     
                    required: "请输入登陆名称"
                },
                principal: {
                    rangelength: "负责人长度在2到10个字符之间"
                },
				business_endtime:{
                    shopTimeBigThan: "营业结束时间必须大于营业开始时间"
                },
                ziti_remark: {
                    maxlength: "自提备注最多可输入250个字符"
                }
            },
            submitHandler: function(form){   
                form.submit();   //提交表单   
            }
        });
    });
</script>
